package cards.controller;

import cards.dao.UserDao;
import cards.entity.CardActivity;
import cards.entity.User;
import cards.service.CardActivityService;
import cards.util.HostHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.List;

@Controller
public class AdminController {
    @Autowired
    private HostHolder localHost;
    @Autowired
    private CardActivityService cardActivityService;

    // 一定是admin 不需要usertype
    @RequestMapping(path="/{usertype}/statics", method= RequestMethod.GET)
    public String displayCardActivityPage3(@PathVariable String usertype, Model model) {
        String category = "statics";
        User user=localHost.getUser();
        List<CardActivity> pageList=cardActivityService.findCardActivity(usertype);
        String header = setHeader(category);

        model.addAttribute("user", user);
        model.addAttribute("topics", pageList);
        model.addAttribute("header", header);
        return category;
    }

    @RequestMapping(path="/{usertype}/parser", method=RequestMethod.GET)
    public String displayCardActivityPage5(@PathVariable String usertype, Model model) {
        String category = "parser";
        User user=localHost.getUser();
        List<CardActivity> pageList=cardActivityService.findCardActivity(usertype);
        String header = setHeader(category);

        model.addAttribute("user", user);
        model.addAttribute("topics", pageList);
        model.addAttribute("header", header);

        return category;
    }

    private String setHeader(String category) {
        switch (category) {
            case "parser":
                return "集卡活动配置";
            case "statics":
                return "集卡活动统计";
            default:
                return "所有活动";
        }
    }

}
